﻿using System;
using System.Collections.Generic;
using System.Linq;
using Windows.UI.Xaml.Data;

namespace Sumc.Client.ModernUI.Converters
{
    public class IEnumerableToFirstItemConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var items = value as IEnumerable<object>;
            if (items != null)
            {
                var position = int.Parse(parameter as string);
                var item = items.ElementAtOrDefault(position);
                if (item != null)
                {
                    return item;
                }
            }

            return value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            return value;
        }
    }
}
